package com.ybb.production.controller;

import com.ybb.production.domain.GarmentProductionBianfei;
import com.ybb.production.domain.GarmentProductionCuttingBedInfo;
import com.ybb.production.dto.GarmentProductionCuttindBedQueryDTO;
import com.ybb.production.dto.GarmentProductionCuttingBedDTO;
import com.ybb.production.dto.GarmentProductionCuttingBedUpdateDTO;
import com.ybb.production.responce.GarmentBianfeiByBundleResp;
import com.ybb.production.responce.GarmentProductionCuttingBedByBoltResp;
import com.ybb.production.responce.GarmentProductionCuttingBedPageResp;
import com.ybb.production.responce.GarmentProductionProgressByBedNoResp;
import com.ybb.production.service.IGarmentProductionCuttingBedInfoService;
import com.yubb.common.annotation.Log;
import com.yubb.common.core.controller.BaseController;
import com.yubb.common.core.domain.AjaxResult;
import com.yubb.common.core.domain.R;
import com.yubb.common.core.page.TableDataInfo;
import com.yubb.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 裁单信息Controller
 *
 * @author ruoyi
 * @date 2023-09-09
 */
@RestController
@RequestMapping("/production/cuttingbed")
@Api(tags = "裁单信息")
public class GarmentProductionCuttingBedInfoController extends BaseController {
    @Autowired
    private IGarmentProductionCuttingBedInfoService garmentProductionCuttingBedInfoService;

    /**
     * 查询裁单信息列表
     */
    @RequiresPermissions("production:cuttingbed:list")
    @GetMapping("/list")
    @ApiOperation(value = "查询裁单信息列表")
    public TableDataInfo<GarmentProductionCuttingBedPageResp> list(GarmentProductionCuttindBedQueryDTO garmentProductionCuttingBedInfo) {
        startPage();
        List<GarmentProductionCuttingBedPageResp> list = garmentProductionCuttingBedInfoService.selectGarmentProductionCuttingBedInfoList(garmentProductionCuttingBedInfo);
        return getDataTable(list);
    }

    /**
     * 获取裁单信息详细信息
     */
    @RequiresPermissions("production:cuttingbed:query")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取裁单信息详细信息")
    public R<GarmentBianfeiByBundleResp> getInfo(@PathVariable("id") Long id) {
        return R.ok(garmentProductionCuttingBedInfoService.selectGarmentProductionCuttingBedInfoById(id));
    }

    /**
     * 新增裁单信息
     */
    @RequiresPermissions("production:cuttingbed:add")
    @Log(title = "裁单信息", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    @ApiOperation(value = "新增裁单信息")
    public R<GarmentProductionCuttingBedInfo> add(@RequestBody @Valid GarmentProductionCuttingBedDTO garmentProductionCuttingBedInfo) {
        return R.ok(garmentProductionCuttingBedInfoService.insertGarmentProductionCuttingBedInfo(garmentProductionCuttingBedInfo));
    }

    /**
     * 修改裁单信息
     */
    @RequiresPermissions("production:cuttingbed:edit")
    @Log(title = "裁单信息", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    @ApiOperation(value = "修改裁单信息")
    public AjaxResult edit(@RequestBody GarmentProductionCuttingBedUpdateDTO bedUpdateDTO) {
        return toAjax(garmentProductionCuttingBedInfoService.updateGarmentProductionCuttingBedInfo(bedUpdateDTO));
    }

    /**
     * 删除裁单信息
     */
    @RequiresPermissions("production:cuttingbed:remove")
    @Log(title = "裁单信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除裁单信息")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(garmentProductionCuttingBedInfoService.deleteGarmentProductionCuttingBedInfoByIds(ids));
    }

    @RequiresPermissions("production:cuttingbed:query")
    @GetMapping(value = "/qryCuttingBedStatistics")
    @ApiOperation(value = "获取裁单表格上方统计")
    public R<GarmentProductionCuttingBedPageResp> qryCuttingBedStatistics() {
        return R.ok(garmentProductionCuttingBedInfoService.qryCuttingBedStatistics());
    }

    @RequiresPermissions("production:cuttingbed:query")
    @GetMapping(value = "/getCuttingBedStatisticsResult/{cuttingBedId}")
    @ApiOperation(value = "裁床进度-完成进度")
    public R<GarmentProductionCuttingBedPageResp> getCuttingBedStatisticsResult(@PathVariable Long cuttingBedId) {
        return R.ok(garmentProductionCuttingBedInfoService.getCuttingBedStatisticsResult(cuttingBedId));
    }

    @RequiresPermissions("production:cuttingbed:query")
    @GetMapping(value = "/getCuttingBedByBundleNo/{cuttingBedId}")
    @ApiOperation(value = "裁床进度-按扎号列表")
    public R<List<GarmentProductionCuttingBedByBoltResp>> garmentProductionCuttingBedByBoltResp(@PathVariable Long cuttingBedId) {
        return R.ok(garmentProductionCuttingBedInfoService.garmentProductionCuttingBedByBoltResp(cuttingBedId));
    }

    @RequiresPermissions("production:cuttingbed:edit")
    @GetMapping(value = "/editQuery")
    @ApiOperation(value = "裁床进度-按扎号列表-修改数量(传裁床id和扎号,调整按钮多传processId)")
    public AjaxResult editQuery(GarmentProductionBianfei garmentProductionBianfei) {
        return toAjax(garmentProductionCuttingBedInfoService.editQuery(garmentProductionBianfei));
    }

    @RequiresPermissions("production:cuttingbed:query")
    @GetMapping(value = "/getCuttingBedByProcess/{cuttingBedId}")
    @ApiOperation(value = "裁床进度-按工序列表")
    public R<List<GarmentProductionProgressByBedNoResp.CuttingBedProcess>> getCuttingBedByProcess(@PathVariable Long cuttingBedId) {
        return R.ok(garmentProductionCuttingBedInfoService.getCuttingBedByProcess(cuttingBedId));
    }
}
